#include "log.h"

namespace hpsfrom_zero {
    logger::logger(const std::string& name = "root")
        : m_name(name), m_level(LogLevel::DEBUG) {
        // 初始化日志器

    }

    void logger::addAppender(std::shared_ptr<LogAppender> appender){
        m_appenders.push_back(appender);
    }

    void logger::delAppender(std::shared_ptr<LogAppender> appender){

        m_appenders.remove(appender);

        // for(auto it = m_appenders.begin(); it != m_appenders.end(); it++){
        //     if(*it == appender){
        //         m_appenders.erase(it);
        //         break;
        //     }
        // }
    }

    void logger::log(LogLevel::Level level, LogEvent::ptr event){
        if(m_level <= level){
            for(auto& i : m_appenders){
                i->log(level, event);
            }
        }
    }

    void logger::debug(LogEvent::ptr event){
        log(LogLevel::DEBUG, event);
    }

    void logger::info(LogEvent::ptr event){
        log(LogLevel::INFO, event);
    }

    void logger::warn(LogEvent::ptr event){
        log(LogLevel::WARN, event);
    }

    void logger::error(LogEvent::ptr event){
        log(LogLevel::ERROR, event);
    }

    void logger::fatal(LogLevel::Level level, LogEvent::ptr event){
        log(LogLevel::FATAL, event);
    }

};